/*
 * Config.cpp
 *
 *  Created on: 2011-10-22
 *      Author: mateusz
 */

#include "Config.h"

#define INFTY 1000000001

using namespace std;

Config::Config() {
	// initial config
	this->maxCustomers = INFTY;
	this->inputFile = "stdin";
	this->outputFile = "stdout";
	this->runTime = 60;
}

Config::~Config() {
}

/**
 *	 read console arguments and parse them
 */
void Config::build(int count, char* args[]) {
	int option_char;

	// parse each argument and check for errors
	while ((option_char = getopt(count, args, "i:o:n:t:")) != -1){
		switch (option_char) {
			case 'i' :
				this->setInputFile(optarg);
				break;
			case 'o' :
				this->setOutputFile(optarg);
				break;
			case 'n' :
				this->setMaxCustomers(atoi(optarg));
				break;
			case 't' :
				this->setRunTime(atoi(optarg));
				break;
			case '?' :
				fprintf(stderr, "usage: %s [-i <input file name>][-o <output file name>][-n <max customers number to analyze>][-t <time to run in seconds (min is 4)>]\n", args[0]);
				break;
		}
	}
}

/**
 * returns maximal customers number parameter
 */
int Config::getMaxCustomers() {
	return this->maxCustomers;
}

/**
 * set max customers numbers parameter
 */
void Config::setMaxCustomers(int maxCustomers) {
	this->maxCustomers = maxCustomers;
}

string Config::getInputFile() {
	return this->inputFile;
}

void Config::setInputFile(string inputFile) {
	this->inputFile = inputFile;
}

void Config::setInputFile(char* inputFile) {
	(this->inputFile).assign(inputFile);
}

string Config::getOutputFile() {
	return this->outputFile;
}

void Config::setOutputFile(string outputFile) {
	this->outputFile = outputFile;
}

void Config::setOutputFile(char* outputFile) {
	(this->outputFile).assign(outputFile);
}

/**
 * set run time in seconds as given time minus 1 second for all other operations than processing cvrp;
 * min run time is 3 seconds
 */

void Config::setRunTime(int seconds){
	(this->runTime) = max((double) (seconds - 1) , 3.0);
}

double Config::getRunTime(){
	return this->runTime;
}
